package zdream.pmfield.stage.buff;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;

import zdream.pmfield.stage.buff.ability.*;
import zdream.pmfield.stage.buff.ailment.*;
import zdream.pmfield.stage.buff.disease.*;
import zdream.pmfield.stage.buff.gain.*;

/**
 * @author Zdream
 * @date 2023-12-09
 * @since 0.0.1
 */
public class Buffs {
	private final Map<String, Function<StageBuff.BuffDescription, StageBuff<?>>> buffFactories = new HashMap<>();

	{
		buffFactories.put(AcidBuff.CATEGORY, description -> new AcidBuff(description.foe));
		buffFactories.put(BoundBuff.CATEGORY, description -> new BoundBuff(description.foe));
		buffFactories.put(BurnBuff.CATEGORY, description -> new BurnBuff(description.foe));
		buffFactories.put(DrowsyBuff.CATEGORY, description -> new DrowsyBuff(description.foe));
		buffFactories.put(FlinchBuff.CATEGORY, description -> new FlinchBuff(description.foe));
		buffFactories.put(FlyingBuff.CATEGORY, description -> new FlyingBuff(description.foe));
		buffFactories.put(FrostbiteBuff.CATEGORY, description -> new FrostbiteBuff(description.foe));
		buffFactories.put(ParalysisBuff.CATEGORY, description -> new ParalysisBuff(description.foe));
		buffFactories.put(PoisonedBuff.CATEGORY, description -> new PoisonedBuff(description.foe));
		buffFactories.put(WetBuff.CATEGORY, description -> new WetBuff(description.foe));
		buffFactories.put(ConfusedBuff.CATEGORY, description -> new ConfusedBuff(description.foe));
		buffFactories.put(SplintersBuff.CATEGORY, description -> new SplintersBuff(description.foe));
		buffFactories.put(FixatedBuff.CATEGORY, description -> new FixatedBuff(description.foe));

		// for abilities
		buffFactories.put(DragonGroupBuff.CATEGORY, DragonGroupBuff::new);
		buffFactories.put(BugGroupBuff.CATEGORY, BugGroupBuff::new);
		buffFactories.put(BirdGroupBuff.CATEGORY, BirdGroupBuff::new);
		buffFactories.put(GhostGroupBuff.CATEGORY, GhostGroupBuff::new);
	}

	public StageBuff<?> createBuff(StageBuff.BuffDescription description) {
		Function<StageBuff.BuffDescription, StageBuff<?>> factory = buffFactories.get(description.category);
		return Objects.requireNonNull(factory).apply(description);
	}
}
